#include <string>
#include <vector>
#include <cstdlib>
#include <fstream>
#include <iostream>

using namespace std;

void makeTitle(){
	#ifdef linux
	system("clear");
	#else
	system("cls");
	#endif
	
	cout << "message [de]coder v0.2" << endl;
	cout << "========================================";
	cout << "========================================" << endl;
	cout << endl;

	return;
}

void code(string arg){
	string in, out;
	string ext1, ext2;
	if(arg.empty()==1){
		cout << "No file input/output file; please specify" << endl;
		cout << "input: ";
		cin >> in;
		cout << "output: ";
		cin >> out;
	}
	else{
		int pos1, pos2, size;
		pos1 = arg.find('.');
		pos2 = arg.find(' ');
		size = arg.size();
		if(pos1 != arg.npos){
			if(pos2 != arg.npos){
				in.append(arg, 0, pos2);
				if(pos2 + 1 < size){
					arg.erase(0, pos2 + 1);
					if(arg.empty() != 1){
						out = arg;
						cout << out << endl;
						if((out.find('.') != arg.npos) and (out.find(' ') != arg.npos)
							and (out.find(' ')>out.find('.'))){
							out.erase(out.find(' '), out.size()-1);
						}
						else if ((out.find('.') == arg.npos and (out.find == )or((out.find('.') 
							!= arg.npos) and (out.find('.') < out.size()-1))){
							cout << "no output extension specified, please enter" << endl;
							cout << "*.";
							cin >> ext2;
						}
					}
				}
				else arg.erase();
			}
			else in = arg;
		}
		else if(pos2 != arg.npos){
			cout << "no input extension specified, please enter" << endl;
			cout << "*.";
			cin >> ext1;
			in.append(arg, 0, pos2);
			in = in + ext1;
			if(pos2 + 1 < size){
				arg.erase(0, pos2 + 1);
			}
			else arg.erase();
		}
	}		
			
	return;
}


int main(){
	makeTitle();
	int state, pos = 0;
	string com, arg, buff, str1 = "code", str2 = "encode";
	while( state != 1234){
		cout << "[> ";
		getline(cin, buff);
		
		com.resize(0);
		pos = buff.find(" ");
		if(pos != buff.npos){
			cout << "Yay!" << endl;
			com.append(buff, 0, pos);
			buff.erase(0, pos + 1);
			arg = buff;
		}
		else com = buff;
		cout << com << endl;
		cout << buff << endl;
		/*cout << buff << buff.size() << com.size() << buff.at(pos);
		while((pos < buff.size()-1)){
			if((buff.at(pos) != ' ') and (buff.at(pos) != '\n')){
				com.at(pos) = buff.at(pos);
				cout << com.at(pos) << buff.at(pos) << pos;
				pos++;
			}
		}		
		cout << 2;
		cout << com;
		bool a = com == str1;
		cout << a << endl;
		cout << com;*/
		
		if((com == str1) or (com == str2)){
			cout << "made it";/*
			pos++;
			while((pos < buff.size())){
				if((buff.at(pos) != ' ') and (buff.at(pos) != '\n')){
					arg.push_back(buff.at(pos));
					pos++;
				}
			}*/
			cout << com << arg << endl;
			code(arg);
			/*makeTitle();*/
		}
		else if(com == "2"){
		}
		else if(com == "3"){
		}
		else if(com == "exit"){
			#ifdef linux
			system("clear");
			#else
			system("cls");
			#endif
			exit(0);
		}
		arg.clear();
		com.clear();
		buff.clear();
		pos = 0;
	}
	return 0;
}
	
